﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;

public partial class Sys_mailcommon : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindGridView(true);
        }
    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        BindGridView(true);
    }
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        string msgid = e.CommandArgument.ToString().Trim();
        if (e.CommandName == "del")
        {
            PM.PMBasic.Mail Mail = new PM.PMBasic.Mail();
            Mail.Delete_Msg(msgid);
            BindGridView(true);
        }
    }
    protected void btnSeach_Click(object sender, ImageClickEventArgs e)
    {
        BindGridView(true);
    }
    protected void btnDel_Click(object sender, EventArgs e)
    {
        PM.PMBasic.Mail Mail = new PM.PMBasic.Mail();
        int num=Mail.Delete_Msg();
        BindGridView(true);
        PM.Code.Web.alertmessage.ShowMsg(this.UpdatePanel1, "执行数量："+num.ToString());
    }
    protected void BindGridView(bool getCount)
    {
        try
        {
            StringBuilder sqlstr = new StringBuilder(" [type]=1 ");
            getWhere(ref sqlstr);
            string field = "msgid,name1,name2,instatus,outstatus,title,createdate,type";
            PM.Code.Web.controlbind.BindGridViewPublicProc(GridView1, AspNetPager1, "View_Messages", "msgid", field, "id", sqlstr.ToString(), getCount);
        }
        catch (System.Exception ex)
        {
            throw ex;
        }
    }

    protected void getWhere(ref StringBuilder sqlstr)
    {
        if (this.txtSender.Text.Trim() != string.Empty)
            sqlstr.Append(" and name1='").Append(this.txtSender.Text.Trim()).Append("'");
        if (this.txtReceiver.Text.Trim() != string.Empty)
            sqlstr.Append(" and name2='").Append(this.txtReceiver.Text.Trim()).Append("'");
        if (this.txtStart.Value.Trim() != string.Empty)
            sqlstr.Append(" and createdate>'").Append(this.txtStart.Value.Trim()).Append("'");
        if (this.txtEnd.Value.Trim() != string.Empty)
            sqlstr.Append(" and createdate<'").Append(this.txtEnd.Value.Trim()).Append("'");
    }
}
